#include "../source/server.hpp"


void OnConnected(const PtrConnection &conn) {
    DEBUG_LOG("NEW CONNECTION:%p", conn.get());
}
void OnClosed(const PtrConnection &conn) {
    DEBUG_LOG("CLOSE CONNECTION:%p", conn.get());
}
void OnMessage(const PtrConnection &conn, Buffer *buf) {
    DEBUG_LOG("%s", buf->GetReadPos());
    buf->MoveReadOffset(buf->ReadableSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());
    //conn->Shutdown();
}

int main()
{
    TCPServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);

    server.SetCloseCallback(OnClosed);
    server.SetConnectedCallBack(OnConnected);
    server.SetMessageCallback(OnMessage);
    server.Start();

    return 0;
}